var $ = require('../../lib/jquery');
var util = require('./common/util');
var nav = require('./common/nav');
var template = require('../tpl/template');
var _header = require('./common/header');
var minHeight = require('./common/minHeight');
var _nav = new nav();
var header = new _header();
var url =location.search;
var id;
url = url.substr(1);
getList(); 
$('.js_left').on('click','.js_row_list',function(){
   //getzixun($(this).data().id)
   console.log(3)
   location.href= $(this).data().link;
  
})
function getList(){
   var s='';
   util.fetch('api/notice/list', {
      type:1,
      currentTime:formatDateTime(),
      size:10,
      from:"",
      search:'',
    }).then(function(res){
      var tpl=template('zi_list',{data:res.data});
      id=res.data[0].id;
      $('.js_left').html(tpl);
      if(url){
         var t=url.split('=')[1];
         getzixun(t);
      
      }else{
         getzixun(id)
      }
      
    })
}
function getzixun(id){
   util.fetch('api/notice/noticeInfo?noticeId='+id).then(function(res){
      $('.title').html(res.data.title)

      $('.content').html((res.data.text || '').replace(/\<br\>/g,'').replace('width','a').replace('height','b'))    
   })
}
 function formatDateTime(data) {
   var date = new Date();
   var y = date.getFullYear();
   var m = date.getMonth() + 1;
   m = m < 10 ? ('0' + m) : m;
   var d = date.getDate();
   d = d < 10 ? ('0' + d) : d;
   var h = date.getHours();
   h = h < 10 ? ('0' + h) : h;
   var minute = date.getMinutes();
   var second = date.getSeconds();
   minute = minute < 10 ? ('0' + minute) : minute;
   second = second < 10 ? ('0' + second) : second;
   return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
 }